package com.lw.main;

import com.lw.util.Constant;
import com.lw.util.GameUtil;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 游戏背景
 */
public class GameBackGround {

    /**
     * 游戏背景图片
     */
    private BufferedImage bkImg;

    public GameBackGround() {
        bkImg = GameUtil.loadBufferedImage(Constant.BK_IMG_PATH);
    }

    /**
     * 绘制图片
     * @param g
     */
    public void draw(Graphics g){
        //填充背景色
        g.setColor(Constant.BK_COLOR);
        g.fillRect(0,0,Constant.WIDTH,Constant.HEIGHT);
        g.setColor(Color.black);

        //得到图片宽高
        int height = bkImg.getHeight();
        int width = bkImg.getWidth();
        //所需图片张数
        int count = Constant.WIDTH/width+1;
        for (int i = 0; i < count; i++) {
            g.drawImage(bkImg,width*i,Constant.HEIGHT-height,null);
        }
    }
}
